package com.sunnay.controller;

import com.sunnay.entity.ShopInfoEntity;
import com.sunnay.service.ShopInfoService;
import com.sunnay.util.R;
import com.sunnay.vo.common.Page;
import com.sunnay.vo.product.ProductDetailVo;
import com.sunnay.vo.product.ProductVo;
import com.sunnay.web.ContextHelper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/shop")
public class ShopController {

    @Resource
    private ShopInfoService shopInfoService;

    @GetMapping("/list")
    public R<List<ShopInfoEntity>> shopList(){
        return R.ok(shopInfoService.shopList(ContextHelper.getSystemUser()));
    }

    @DeleteMapping
    public R<Boolean> deleteShop(@RequestParam("id") String id){
        shopInfoService.deleteShop(ContextHelper.getSystemUser(),id);
        return R.ok();
    }

    @GetMapping("/page")
    public R<List<ProductVo>> productList(@RequestParam("shopUri") String shopUri, Page page){
        return R.ok(shopInfoService.productList(shopUri,ContextHelper.getSystemUser(),page));
    }

    @GetMapping("/flush")
    public R<ProductDetailVo> productFlush(@RequestParam("saleUri") String saleUri){
        return R.ok(shopInfoService.productFlush(saleUri,ContextHelper.getSystemUser()));
    }

    @GetMapping("/cancel")
    public R<Boolean> cancelBind(@RequestParam("id") String id){
        shopInfoService.cancelBind(ContextHelper.getSystemUser(),id);
        return R.ok();
    }

    @GetMapping("/top")
    public R<Boolean> top(@RequestParam("id") String id){
        shopInfoService.topShop(id,ContextHelper.getSystemUser());
        return R.ok();
    }

    @GetMapping("/cancel-top")
    public R<Boolean> cancelTop(@RequestParam("id") String id){
        shopInfoService.cancelTop(id,ContextHelper.getSystemUser());
        return R.ok();
    }
}
